package com.efast.dmom.mes.datahandlers.entity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.mes.bean.Part;
import com.efast.dmom.mes.bean.PartAlternate;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.PartAlternateDao;
import com.efast.dmom.mes.datahandlers.base.PartRelateDataHandler;
import com.efast.dmom.mes.entity.PartAlternateEntity;
import com.efast.dmom.mes.util.BaseEntityDataUtil;

@Component
public class PartAlternateDataHandler extends PartRelateDataHandler<PartAlternate>{
	@Autowired
	private PartAlternateDao partAlternateDao;
	
	@Override
	public ResultBean save(PartAlternate obj) {
		ResultBean resultBean = new ResultBean();
		if(obj==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater is null");
			return resultBean;
		}
		PartAlternateEntity entity = obj.getInnerData();
		if(entity==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater innerdata is null");
			return resultBean;
		}
		
		BaseEntityDataUtil.setBaseEntityData(entity);
		int save = partAlternateDao.save(entity);
		if(save>0) {
			resultBean.setSuccess(true);
		}else {
			resultBean.setSuccess(false);
			resultBean.setMessage("insert fail");
		}

		return resultBean;
	}

	@Override
	public ResultBean update(PartAlternate obj) {
		ResultBean resultBean = new ResultBean();
		partAlternateDao.update(obj.getInnerData());
		return resultBean;
	}

	@Override
	public ResultBean delete(PartAlternate obj) {
		ResultBean resultBean = new ResultBean();
		partAlternateDao.delete(obj.getInnerData());
		return resultBean;
	}

	@Override
	public PartAlternate getById(long id) {
		PartAlternateEntity entity = partAlternateDao.getById(id);
		PartAlternate partAlternate = new PartAlternate();
		partAlternate.setInnerData(entity);
		return partAlternate;
	}
	
	@Override
	public ResultBean saveBatch(List<PartAlternate> obj) {
		return null;
	}

	@Override
	public ResultBean updateBatch(List<PartAlternate> obj) {
		return null;
	}

	@Override
	public ResultBean deleteBatch(List<PartAlternate> obj) {
		return null;
	}
	
	public List<PartAlternate> getByPartId(long id){
		return null;
	}
	public List<PartAlternate> getByAlternatePartId(long id){
		return null;
	}
	public List<Part> getAlternatePartByPartId(long id){
		return null;
	}
	public List<Part> getPartByAlternatePartId(long id){
		return null;
	}
	public PartAlternate getByPartIdAndAlternateId(long partId,long alternatePartId){
		PartAlternateEntity pae = partAlternateDao.getByPartIdAndAlternateId(partId,alternatePartId);
		if(pae!=null) {
			PartAlternate partAlternate = new PartAlternate();
			partAlternate.setInnerData(pae);
			return partAlternate;
		}
		return null;
	}
}
